package com.jsm.tf.net.protocol.serialize;

import com.google.gson.Gson;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class GsonSerializer implements Serializer {

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
        return new Gson().fromJson(new String(bytes, StandardCharsets.UTF_8), clazz);
    }

    @Override
    public <T> byte[] serialize(T object) throws IOException {
        return new Gson().toJson(object).getBytes(StandardCharsets.UTF_8);
    }
}
